package com.example.controller;

import com.example.log.InitLog;
import com.example.log.UpdateLog;
import com.example.pojo.BusNews;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.BusNewsService;
import jakarta.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/BusNews")
public class BusNewsController {
    @Autowired
    private BusNewsService busNewsService;
    @GetMapping
    public Result busNews(){
        return busNewsService.getList();
    }

    @GetMapping("/page")
    public Result pageList(@ModelAttribute PageBean pageBean, @Nullable @RequestParam("name") String name){
        log.info("校车资讯的分页查询,参数pageBean: {} 模糊匹配关键词: {}", pageBean,name);
        return busNewsService.pageList(pageBean,name);
    }

    @PostMapping("/add")
    public Result addNus(@RequestBody BusNews busNews){
        log.info("新增校车资讯,关键参数:{}",busNews.someMsg());
        return busNewsService.addBusNews(busNews);
    }

    @DeleteMapping("/delete")
    public Result DeleteNusByIds(@RequestParam("ids") List<Integer> ids){
        log.info("根据ids删除校车资讯,参数: {}",ids);
        return busNewsService.deleteByIds(ids);
    }

    @PutMapping("/update")
    public Result updateBusNews(@RequestBody BusNews busNews){
        log.info("修改校车资讯,关键参数: {}",busNews.someMsg());
        return busNewsService.updateBusNews(busNews);
    }
}
